<?php
require("conn.php");
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$sid = $_POST["sid"];
$published = $_POST["published"];
$image =  $_POST["image"];
$tag = $_POST["tag"];

$vi_title=$_POST["vi_title"];
$vi_summary=$_POST["vi_summary"];
$vi_content=$_POST["vi_content"];
$en_title=$_POST["en_title"];
$en_summary= $_POST["en_summary"];
$en_content=$_POST["en_content"];
$art_order = $_POST["art_order"];
$created_date= date("Y/m/d");
$user_id = $_SESSION["UserID"];
$featured = $_POST["featured"];
$Menu = $_POST["parent_id"];
$sql=sprintf("insert into tblarticle (section_id,published,image,tag,vi_title,vi_summary,vi_content,en_title,en_summary,en_content, art_order, created_date,user_id,featured)   values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
	$sid,$published,$image, $tag,$vi_title,$vi_summary,$vi_content,$en_title,$en_summary,$en_content,$art_order ,$created_date,$user_id,$featured);

		
$rs=mysql_query($sql) or die(mysql_error());
			 
if(!$rs)
{
	
?>
	<script language="javascript">
		alert("Thêm bài viết không thành công");
		
	</script>
<?php
}
else
{
	
	
	$sql=sprintf("insert into tblmenu (vi_name,en_name,url,tblmenu.order,parent_id,featured)   values('%s','%s','/view/%s','%s','%s','%s')",
	$vi_title,$en_title,mysql_insert_id(),$art_order, $Menu,$featured);
	$rs=mysql_query($sql) or die(mysql_error());
	
?>
	<script language="javascript">
		alert("Thêm bài viết thành công");
		window.location="article";
	</script>
<?php
}

?>